package javacommon.util;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

public class WebPost {
	public void toRequest(String url, String method) {
		try {
			URL addr = new URL(url);

			HttpURLConnection httpUrl = (HttpURLConnection) addr.openConnection();
			httpUrl.setDoOutput(true);
			httpUrl.setRequestMethod(method);// POST||GET
			httpUrl.setUseCaches(false);
			httpUrl.setRequestProperty("Content-type","application/x-java-serialized-object");
			
			BufferedOutputStream hurlBufOus = new BufferedOutputStream(httpUrl.getOutputStream());
			BufferedInputStream hurlBufIns = new BufferedInputStream(httpUrl.getInputStream());
			
			hurlBufOus.flush();
			
			if (hurlBufOus != null)hurlBufOus.close();
			if (hurlBufIns != null)hurlBufIns.close();
			
			httpUrl.disconnect();

		} catch (MalformedURLException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
